package com.fengze.business.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.fengze.common.annotation.Log;
import com.fengze.common.core.controller.BaseController;
import com.fengze.common.core.domain.AjaxResult;
import com.fengze.common.enums.BusinessType;
import com.fengze.business.domain.ReimbursementRecord;
import com.fengze.business.service.IReimbursementRecordService;
import com.fengze.common.utils.poi.ExcelUtil;
import com.fengze.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 报销记录Controller
 * 
 * @author lug
 * @date 2024-02-28
 */
@RestController
@RequestMapping("/reimbursement/record")
public class ReimbursementRecordController extends BaseController
{
    @Autowired
    private IReimbursementRecordService reimbursementRecordService;

    /**
     * 查询报销记录列表
     */
    @PreAuthorize("@ss.hasPermi('reimbursement:record:list')")
    @GetMapping("/list")
    public TableDataInfo list(ReimbursementRecord reimbursementRecord)
    {
        startPage();
        List<ReimbursementRecord> list = reimbursementRecordService.selectReimbursementRecordList(reimbursementRecord);
        return getDataTable(list);
    }

    /**
     * 导出报销记录列表
     */
    @PreAuthorize("@ss.hasPermi('reimbursement:record:export')")
    @Log(title = "报销记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ReimbursementRecord reimbursementRecord)
    {
        List<ReimbursementRecord> list = reimbursementRecordService.selectReimbursementRecordList(reimbursementRecord);
        ExcelUtil<ReimbursementRecord> util = new ExcelUtil<ReimbursementRecord>(ReimbursementRecord.class);
        util.exportExcel(response, list, "报销记录数据");
    }

    /**
     * 获取报销记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('reimbursement:record:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(reimbursementRecordService.selectReimbursementRecordById(id));
    }

    /**
     * 新增报销记录
     */
    @PreAuthorize("@ss.hasPermi('reimbursement:record:add')")
    @Log(title = "报销记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(ReimbursementRecord reimbursementRecord, MultipartFile [] files)
    {
        return toAjax(reimbursementRecordService.insertReimbursementRecordWithFiles(reimbursementRecord,files));
    }

    /**
     * 修改报销记录
     */
    @PreAuthorize("@ss.hasPermi('reimbursement:record:edit')")
    @Log(title = "报销记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(ReimbursementRecord reimbursementRecord,MultipartFile [] files)
    {
        return toAjax(reimbursementRecordService.updateReimbursementRecordWithFiles(reimbursementRecord,files));
    }

    /**
     * 删除报销记录
     */
    @PreAuthorize("@ss.hasPermi('reimbursement:record:remove')")
    @Log(title = "报销记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(reimbursementRecordService.deleteReimbursementRecordByIds(ids));
    }

    /**
     * 审核报销记录
     */
    @PreAuthorize("@ss.hasPermi('reimbursement:record:examine')")
    @Log(title = "报销记录审核", businessType = BusinessType.UPDATE)
    @PutMapping("/examine/{id}")
    public AjaxResult examine(@PathVariable long id)
    {
        int count = reimbursementRecordService.examineInfo(id);
        if(count > 0){
            return AjaxResult.success("审核成功");
        }
        return AjaxResult.error("审核失败");
    }


    /**
     * 审核报销记录
     */
    @PreAuthorize("@ss.hasPermi('reimbursement:record:payment')")
    @Log(title = "报销记录打款", businessType = BusinessType.UPDATE)
    @PutMapping("/payment/{id}")
    public AjaxResult paymentMoney(@PathVariable long id)
    {
        int count = reimbursementRecordService.paymentMoney(id);
        if(count > 0){
            return AjaxResult.success("打款成功");
        }
        return AjaxResult.error("打款失败");
    }
}
